<template>
  <div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline" style="text-align: left">
      <el-form-item label="标题名称">
        <el-input v-model="formInline.title"></el-input>
      </el-form-item>
      <el-form-item label="问题类型">
        <el-select v-model="formInline.typeId" placeholder="请选择">
          <el-option label="请选择" :value="0"></el-option>
          <el-option label="常见问题" :value="1"></el-option>
          <el-option label="其他问题" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getcustomer">查询</el-button>
        <el-button @click="resetForm">重置</el-button>
        <el-button type="primary" @click="postecustomer">新增</el-button>
      </el-form-item>
    </el-form>
    <br>
    <el-table ref="multipleTable" :data="tableData" border tooltip-effect="dark" style="width: 100%"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection"> </el-table-column>
      <el-table-column prop="id" label="序号" align="center"> </el-table-column>
      <el-table-column prop="title" label="标题" align="center"> </el-table-column>
      <el-table-column prop="typeId" label="类型" align="center">
        <template slot-scope="scope">
          <div v-if="scope.row.typeId == 1">常见问题</div>
          <div v-else-if="scope.row.typeId == 2">其他问题</div>
        </template>
      </el-table-column>
      <el-table-column prop="keyword" label="关键字" align="center">
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-link type="warning" @click="updatecustomer(scope.row)">编辑</el-link>
          <el-link type="danger" @click="deletecustomer(scope.row)">删除</el-link>
        </template>
      </el-table-column>
    </el-table>
    <br>
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :current-page="formInline.pageIndex" :page-sizes="[10, 20, 30, 40]" :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper" :total="count">
    </el-pagination>

    <el-dialog title="收货地址" :visible.sync="dialogpostVisible">
      <el-form :model="formData">
        <el-form-item label="标题" :label-width="formLabelWidth">
          <el-input v-model="formData.title" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="问题类型" :label-width="formLabelWidth">
          <el-select v-model="formData.typeId" placeholder="请选择">
            <el-option label="常见问题" :value="1"></el-option>
            <el-option label="其他问题" :value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关键字" :label-width="formLabelWidth">
          <el-input v-model="formData.keyword" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="内容" :label-width="formLabelWidth">
          <el-input v-model="formData.content" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addcustomer">保存</el-button>
        <el-button type="primary" @click="dialogpostVisible = false">取消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="收货地址" :visible.sync="dialogputVisible">
      <el-form :model="formData">
        <el-form-item label="标题" :label-width="formLabelWidth">
          <el-input v-model="formData.title" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="问题类型" :label-width="formLabelWidth">
          <el-select v-model="formData.typeId" placeholder="请选择">
            <el-option label="常见问题" :value="1"></el-option>
            <el-option label="其他问题" :value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关键字" :label-width="formLabelWidth">
          <el-input v-model="formData.keyword" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="内容" :label-width="formLabelWidth">
          <el-input v-model="formData.content" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="putcustomer">保存</el-button>
        <el-button type="primary" @click="dialogputVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  getcustomerapi,
  postcustomerapi,
  putcustomerapi,
  deletecustomerapi,
} from "@/api/parkManage/Customer";
export default {
  data() {
    return {
      tableData: [],
      formInline: {
        pageIndex: 1,
        pageSize: 10,
        title: "",
        typeId: 0,
      },
      count: 0,
      dialogpostVisible: false,
      dialogputVisible: false,
      formLabelWidth: "120px",
      formData: {},
    };
  },
  methods: {
    getcustomer() {
      getcustomerapi(this.formInline).then((res) => {
        this.tableData = res.data.data;
        this.count = res.data.totalCount;
      });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.formInline.pageSize = val;
      this.getcustomer();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.formInline.pageIndex = val;
      this.getcustomer();
    },
    resetForm() {
      this.formInline.title = "";
      this.formInline.typeId = 0;
    },
    handleSelectionChange(val) { },
    postecustomer() {
      this.formData = {};
      this.dialogpostVisible = true;
    },
    addcustomer() {
      postcustomerapi(this.formData).then((res) => {
        if (res.data.message == "操作成功") {
          this.$message({
            message: "保存成功",
            type: "success",
          });
          this.getcustomer();
          this.dialogpostVisible = false;
        } else {
          this.$message({
            message: "保存失败",
            type: "error",
          });
        }
      });
    },
    updatecustomer(row) {
      this.dialogputVisible = true;
      this.formData = row;
    },
    putcustomer() {
      putcustomerapi(this.formData).then((res) => {
        if (res.data.message == "操作成功") {
          this.$message({
            message: "保存成功",
            type: "success",
          });
          this.getcustomer();
          this.dialogputVisible = false;
        } else {
          this.$message({
            message: "保存失败",
            type: "error",
          });
        }
      });
    },
    deletecustomer(row) {
      if (confirm("记录数据删除将无法恢复，确认删除吗？")) {
        deletecustomerapi(row).then((res) => {
          if (res.data.message == "操作成功") {
            this.$message({
              message: "删除成功",
              type: "success",
            });
            this.getcustomer();
          } else {
            this.$message({
              message: "删除失败",
              type: "error",
            });
          }
        });
      }
    },
  },
  created() {
    this.getcustomer();
  },
};
</script>
<style></style>